package com.hoodbrains.insideloc.maps;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Paint.Style;
import android.util.Log;

import com.hoodbrains.insideloc.utils.Catalog;

public class Rayon extends DrawableObject {
	private String type;
	
	public String getType() {
		return type;
	}

	/**
	 * 
	 */
	public void configurePaint(){
		Log.e("Rayon", "paint");
		paint.setStrokeWidth(1.0f);
		
		String color = getColor();
		Log.e("Rayon", "color: " + color);
		
		paint.setColor(
				Color.parseColor(getColor()));
//				Integer.parseInt(color.substring(1), 16) );
//		Log.e("test final 1", getColor());
		paint.setStyle(Style.FILL);
	}
	
	/**
	 * Draw a rectangle  
	 * @param canvas
	 * @param topleftx
	 * @param toplefty
	 * @param width
	 * @param height
	 */
	public void draw(Canvas canvas, int topleftx, int toplefty, int width, int height) {
		super.draw(canvas);
		DrawingTools.drawRectangle(canvas,this.paint,new Point(topleftx,toplefty), width, height);
	}
	
	/**
	 * 
	 * @param elem
	 * @return
	 */
	public static Rayon deserialize(Element elem) {
		Rayon rayon = new Rayon();
		rayon.type = elem.getAttribute("type");
			Log.e("Rayon", rayon.type);
			Log.i("Rayon", rayon.type+" : "+rayon.getColor());
		return rayon;
	}
	
	/**
	 * 
	 * @return a String representation of the Color in RGB
	 */
	public String getColor(){
		return Catalog.getInstance().getColor(this.type);
	}
	
	/**
	 * Serialize the object
	 * @param doc
	 * @return
	 */
	public Element serialize(Document doc) {
		Element elem = doc.createElement("rayon");
		elem.setAttribute("type", type);
		
		return elem;
	}
	
	protected Rayon(String type){
		super();
		this.type=type;
	}
	
	public Rayon(){
		super();
	}
	
}
